/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2015年3月17日         luwei
 */

package com.coocaa.app.gamecenter.framework.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.view.View;

import com.coocaa.x.framework.utils.NativeImageCache.SmartBitmap;

public class MultiImageView extends View {
    private int mDivide = 0;
    private SmartBitmap[] mBitmaps = null;

    public MultiImageView(Context context) {
        super(context);
    }

    public void setDivide(int divide) {
        this.mDivide = divide;
    }

    public void setImages(SmartBitmap[] bitmaps) {
        this.mBitmaps = bitmaps;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (mBitmaps != null) {
            int left = getWidth();
            int i = 0;
            for (SmartBitmap bitmap : mBitmaps) {
                if (bitmap != null && bitmap.get() != null) {
                    if (i == 0) {
                        left = left - bitmap.get().getWidth();
                    } else {
                        left = left - bitmap.get().getWidth() - mDivide;
                    }
                    i++;
                    canvas.drawBitmap(bitmap.get(), left, 0, null);
                }
            }
        }
        super.onDraw(canvas);
    }

    public void destory() {
        for (SmartBitmap bitmap : mBitmaps) {
            if (bitmap != null) {
                bitmap.recycle();
            }
        }
    }
}
